﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YJKRevitColumn.ColumnModule.DataDefine;
using YArchitech.Controls;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArchUtils.StructurePoleSuit;
using YJKArchUtils.Utils;
using YJKGeometryFuncs;

namespace YJKRevitColumn.ColumnModule
{
	public class ImportColumnControler
	{
		public ImportColumnControler(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
			this.m_Doc = cmdData.Application.ActiveUIDocument.Document;
		}

		public Result Import(string middleFilePath, ref string message)
		{
			Document doc = this.m_Doc;
			if (doc.IsFamilyDocument)
			{
				message = "当前文档不是工程文档";
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			if ((int)doc.ActiveView.ViewType != 1)
			{
				message = "当视图不是楼层视图";
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			List<WallInfos> list = null;
			XYZ selecetBoxMin = null;
			XYZ selecetBoxMax = null;
			Result result = this.SelectClosedCurvesByWall(out list, ref selecetBoxMin, ref selecetBoxMax, ref message);
			if (result != Autodesk.Revit.UI.Result.Succeeded)
			{
				return result;
			}
			List<string> familiyPathList = new List<string>();
			result = this.CreateFamiliesAndSymbols(ref familiyPathList, ref message);
			if (result != Autodesk.Revit.UI.Result.Succeeded)
			{
				return result;
			}
			result = this.LoadFamiliesFile(familiyPathList, ref message);
			if (result != Autodesk.Revit.UI.Result.Succeeded)
			{
				return result;
			}
			return this.CreateElements(selecetBoxMin, selecetBoxMax, ref message);
		}

		private Result SelectClosedCurvesByWall(out List<WallInfos> wallInfoList, ref XYZ selecetBoxMin, ref XYZ selecetBoxMax, ref string message)
		{
			List<Element> selElements = null;
			Result result;
			for (;;)
			{
				selElements = new List<Element>();
				wallInfoList = new List<WallInfos>();
				result = this.SelectWalls(ref selElements, ref wallInfoList, ref selecetBoxMin, ref selecetBoxMax);
				if (result != Autodesk.Revit.UI.Result.Succeeded)
				{
					break;
				}
				if (wallInfoList.Count >= 1)
				{
					goto Block_2;
				}
			}
			return result;
			Block_2:
			double useExtendLength = Common.MMToFeet(1000.0);
			List<ColumnProfilePart> partList = WallInfoHandler.MakeLstClolumnProfilePart(wallInfoList, useExtendLength);
			Selection selection = this.m_Revit.Application.ActiveUIDocument.Selection;
			RevitVersionFuncs.SetSelection(selection, selElements);
			List<Material> allMaterial = Common.GetAllMaterial(this.m_Revit.Application.ActiveUIDocument.Document);
			ImportSettingForm importSettingForm = new ImportSettingForm(this.m_Revit, partList, selecetBoxMin, selecetBoxMax, allMaterial);
			if (importSettingForm.ShowDialog() != DialogResult.OK)
			{
				RevitVersionFuncs.ClearSelection(selection);
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			this.m_TopLevel = importSettingForm.TopLevel;
			if (this.m_TopLevel == null)
			{
				YJKMessageBox.Show("无法生成暗柱，当前标高的上一层标高不存在");
				return Autodesk.Revit.UI.Result.Succeeded;
			}
			this.m_BottomLevel = this.m_Doc.ActiveView.GenLevel;
			double val = importSettingForm.TopLevel.Elevation - this.m_Doc.ActiveView.GenLevel.Elevation;
			if (importSettingForm.cmbHeight.Text.Contains("当前层高"))
			{
				AssistFunc.feetToMM(val);
			}
			else
			{
				try
				{
					Convert.ToDouble(importSettingForm.cmbHeight.Text);
				}
				catch
				{
					AssistFunc.feetToMM(val);
				}
			}
			try
			{
				this.m_BottomOffset = Common.MMToFeet(Convert.ToDouble(importSettingForm.cmbBaseOffset.Text));
			}
			catch
			{
				this.m_BottomOffset = Common.MMToFeet(0.0);
			}
			this.m_material = importSettingForm.ColumnMaterial;
			RevitVersionFuncs.ClearSelection(selection);
			List<Curve> list = new List<Curve>();
			List<List<Curve>> curvesList = importSettingForm.ProfileCurves(ref list);
            if (this.SearchColumnInfos(curvesList, importSettingForm.FamilyName, ref message) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Result SelectWalls(ref List<Element> walls, ref List<WallInfos> wallInfosList, ref XYZ selecetBoxMin, ref XYZ selecetBoxMax)
		{
			Document doc = this.m_Doc;
			Autodesk.Revit.DB.View activeView = this.m_Revit.Application.ActiveUIDocument.ActiveView;
			double elevation = this.m_Revit.Application.ActiveUIDocument.ActiveView.GenLevel.Elevation;
			List<Level> sortLevels = Common.GetSortLevels(doc, elevation, double.MaxValue);
			List<double> list = new List<double>();
			using (List<Level>.Enumerator enumerator = sortLevels.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Level level = enumerator.Current;
					int num = list.FindIndex((double value) => YJKArchUtils.Utils.Geometry.IsEqual(value, level.Elevation));
					if (-1 == num)
					{
						list.Add(level.Elevation);
					}
				}
			}
			double num2 = elevation + Common.MMToFeet(4000.0);
			if (list.Count > 1)
			{
				num2 = list[1];
			}
			PickedBox pickedBox = null;
			Selection selection = this.m_Revit.Application.ActiveUIDocument.Selection;
			try
			{
				pickedBox = selection.PickBox((Autodesk.Revit.UI.Selection.PickBoxStyle)2, "选择一组相交墙");
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			double x = pickedBox.Min.X;
			double x2 = pickedBox.Max.X;
			double y = pickedBox.Min.Y;
			double y2 = pickedBox.Max.Y;
			if (YJKArchUtils.Utils.Geometry.LessThan(pickedBox.Max.X, pickedBox.Min.X))
			{
				x = pickedBox.Max.X;
				x2 = pickedBox.Min.X;
			}
			if (YJKArchUtils.Utils.Geometry.LessThan(pickedBox.Max.Y, pickedBox.Min.Y))
			{
				y = pickedBox.Max.Y;
				y2 = pickedBox.Min.Y;
			}
			selecetBoxMin = new XYZ(x, y, elevation + Common.MMToFeet(10.0));
			selecetBoxMax = new XYZ(x2, y2, num2 - Common.MMToFeet(10.0));
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(selecetBoxMin, selecetBoxMax));
			IList<Element> source = new FilteredElementCollector(doc, activeView.Id).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements();
			List<Element> list2 = new List<Element>();
			list2.AddRange(from n in source
			where n.LevelId == this.m_Doc.ActiveView.GenLevel.Id
			select n);
			if (list2.Count < 2)
			{
				YJKMessageBox.Show("至少框选两个相交的墙");
				return Autodesk.Revit.UI.Result.Succeeded;
			}
			foreach (Element element in list2)
			{
                if (element is Wall && (int)(element as Wall).WallType.Kind == 2)
				{
					YJKMessageBox.Show("所选墙体中包含叠层墙，无法生成暗柱!");
					return Autodesk.Revit.UI.Result.Succeeded;
				}
			}
			double thickness = 0.0;
			double num3 = 0.0;
			XYZ xyz = XYZ.Zero;
			XYZ xyz2 = XYZ.Zero;
			for (int i = 0; i < list2.Count; i++)
			{
				Curve wallOffsetCurve = this.GetWallOffsetCurve(list2[i], ref thickness);
				xyz = wallOffsetCurve.GetEndPoint(0);
				xyz2 = wallOffsetCurve.GetEndPoint(1);
				LocationCurve locationCurve = (list2[i] as Wall).Location as LocationCurve;
				ElementArray elementArray = locationCurve.get_ElementsAtJoin(0);
				List<Wall> list3 = new List<Wall>();
				foreach (object obj in elementArray)
				{
					list3.Add(obj as Wall);
				}
				List<Element> list4 = new List<Element>();
				list4.AddRange(list2);
				using (List<Wall>.Enumerator enumerator4 = list3.GetEnumerator())
				{
					while (enumerator4.MoveNext())
					{
						Wall item = enumerator4.Current;
						if (list4.Find((Element n) => n.Id.IntegerValue == item.Id.IntegerValue) == null)
						{
							ElementArray elementArray2 = locationCurve.get_ElementsAtJoin(1);
							list3.Clear();
							IEnumerator enumerator3 = elementArray2.GetEnumerator();
							{
								while (enumerator3.MoveNext())
								{
									object obj2 = enumerator3.Current;
									list3.Add(obj2 as Wall);
								}
								break;
							}
						}
					}
				}
				Curve curve = wallOffsetCurve.Clone();
				curve.MakeUnbound();
				for (int j = 0; j < list3.Count; j++)
				{
					if (list3[j].Id.IntegerValue != list2[i].Id.IntegerValue)
					{
						Curve wallOffsetCurve2 = this.GetWallOffsetCurve(list3[j], ref num3);
						IntersectionResultArray intersectionResultArray = null;
						Curve curve2 = wallOffsetCurve2.Clone();
						curve2.MakeUnbound();
						curve.Intersect(curve2, out intersectionResultArray);
						if (intersectionResultArray != null)
						{
							XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
							if (YJKGeometryFuncs.Geometry.LessThan(xyz.DistanceTo(xyzpoint), xyz2.DistanceTo(xyzpoint)))
							{
								xyz = xyzpoint;
							}
							else
							{
								xyz2 = xyzpoint;
							}
						}
					}
				}
				if (wallOffsetCurve is Line)
				{
					wallInfosList.Add(new WallInfos(xyz, xyz2, 0.0, thickness, list2[i].Id, list2[i].Id));
				}
				else
				{
					Arc arc = wallOffsetCurve as Arc;
					wallInfosList.Add(new WallInfos(xyz, xyz2, YJKArchUtils.Utils.Geometry.GetBulge(xyz, xyz2, arc.Center, true), thickness, list2[i].Id, list2[i].Id));
				}
			}
			WallInfoHandler.SplitWallInfo(this.m_Revit, ref wallInfosList);
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Curve GetWallOffsetCurve(Element elem, ref double dCoreThickness)
		{
			Wall wall = elem as Wall;
			Curve curve = (wall.Location as LocationCurve).Curve;
			double thicknessWithWallType;
			if (curve is Line)
			{
				XYZ direction = (curve as Line).Direction;
				XYZ orientation = wall.Orientation;
				Transform transform = Transform.CreateTranslation(orientation * (wall.Width / 2.0));
				Curve curve2 = curve.CreateTransformed(transform) as Line;
				dCoreThickness = this.GetThicknessWithWallType(wall.WallType, true);
				thicknessWithWallType = this.GetThicknessWithWallType(wall.WallType, false);
				transform = Transform.CreateTranslation(-orientation * (dCoreThickness / 2.0 + thicknessWithWallType));
				return curve2.CreateTransformed(transform) as Line;
			}
			Arc arc = curve as Arc;
			dCoreThickness = this.GetThicknessWithWallType(wall.WallType, true);
			thicknessWithWallType = this.GetThicknessWithWallType(wall.WallType, false);
			double num = arc.Radius - wall.Width / 2.0 + thicknessWithWallType + dCoreThickness / 2.0;
			XYZ center = arc.Center;
			XYZ endPoint = arc.GetEndPoint(0);
			XYZ endPoint2 = arc.GetEndPoint(1);
			XYZ xyz = arc.Evaluate(0.5, true);
			XYZ xyz2 = (endPoint - center).Normalize();
			XYZ xyz3 = (endPoint2 - center).Normalize();
			XYZ xyz4 = (xyz - center).Normalize();
			XYZ xyz5 = center + xyz2 * num;
			XYZ xyz6 = center + xyz3 * num;
			XYZ xyz7 = center + xyz4 * num;
			return Arc.Create(xyz5, xyz6, xyz7);
		}

		private double GetThicknessWithWallType(WallType wallType, bool bCore)
		{
			double num = 0.0;
			CompoundStructure compoundStructure = wallType.GetCompoundStructure();
			if (compoundStructure == null)
			{
				return num;
			}
			int firstCoreLayerIndex = compoundStructure.GetFirstCoreLayerIndex();
			int lastCoreLayerIndex = compoundStructure.GetLastCoreLayerIndex();
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			int count = layers.Count;
			new List<int>();
			if (bCore)
			{
				for (int i = 0; i < count; i++)
				{
					CompoundStructureLayer compoundStructureLayer = layers[i];
					if (i <= lastCoreLayerIndex && i >= firstCoreLayerIndex)
					{
						num += compoundStructureLayer.Width;
					}
				}
			}
			else
			{
				for (int j = 0; j < count; j++)
				{
					CompoundStructureLayer compoundStructureLayer2 = layers[j];
					if (j <= lastCoreLayerIndex && j >= firstCoreLayerIndex)
					{
						break;
					}
					num += compoundStructureLayer2.Width;
				}
			}
			return num;
		}

		private bool IfWallIsWallInfo(Wall inputWall)
		{
			return inputWall.ParametersMap.Contains("已附着顶部") || inputWall.ParametersMap.Contains("Top is Attached");
		}

		private Result SearchColumnInfos(List<List<Curve>> curvesList, string familyName, ref string message)
		{
			StructureLoopSearcher structureLoopSearcher = new StructureLoopSearcher(this.m_Revit, true);
			try
			{
				List<SectionLoop> list = new List<SectionLoop>();
				BoundingBoxUV boundingBoxUV = null;
				List<List<Curve>> list2 = new List<List<Curve>>();
				foreach (List<Curve> curveList in curvesList)
				{
					List<Curve> edgeLoopsByEdgeList = structureLoopSearcher.GetEdgeLoopsByEdgeList(curveList);
					if (edgeLoopsByEdgeList.Count < 1)
					{
						message = "不是单独的封闭区域";
						return Autodesk.Revit.UI.Result.Failed;
					}
					list2.Add(edgeLoopsByEdgeList);
					foreach (Curve curve in edgeLoopsByEdgeList)
					{
						if (curve.GetType() == typeof(Line))
						{
							Line line = curve as Line;
							if (boundingBoxUV == null)
							{
								boundingBoxUV = YJKArchUtils.Utils.Geometry.CalculateBoundingBox2D(line);
							}
							else
							{
								BoundingBoxUV boundingBoxUV2 = YJKArchUtils.Utils.Geometry.CalculateBoundingBox2D(line);
								if (boundingBoxUV2 != null)
								{
									boundingBoxUV = YJKArchUtils.Utils.Geometry.BoundingBoxesMerge(boundingBoxUV, boundingBoxUV2);
								}
							}
						}
						else if (curve.GetType() == typeof(Arc))
						{
							Arc arc = curve as Arc;
							if (boundingBoxUV == null)
							{
								boundingBoxUV = YJKArchUtils.Utils.Geometry.CalculateBoundingBox2D(arc);
							}
							else
							{
								BoundingBoxUV boundingBoxUV3 = YJKArchUtils.Utils.Geometry.CalculateBoundingBox2D(arc);
								if (boundingBoxUV3 != null)
								{
									boundingBoxUV = YJKArchUtils.Utils.Geometry.BoundingBoxesMerge(boundingBoxUV, boundingBoxUV3);
								}
							}
						}
					}
				}
				UV uv = null;
				foreach (List<Curve> list3 in list2)
				{
					uv = boundingBoxUV.Min + (boundingBoxUV.Max - boundingBoxUV.Min) / 2.0;
					Transform transform = RevitVersionFuncs.CreateTranslation(new XYZ(-uv.U, -uv.V, 0.0));
					List<YJKArchUtils.StructurePoleSuit.Edge> list4 = new List<YJKArchUtils.StructurePoleSuit.Edge>();
					foreach (Curve curve2 in list3)
					{
						YJKArchUtils.StructurePoleSuit.Edge item;
						if (curve2.GetType() == typeof(Line))
						{
							Line curve3 = this.TranslateLine(curve2 as Line, transform);
							XYZ hyendPoint = curve3.GetEndPoint(0);
							XYZ hyendPoint2 = curve3.GetEndPoint(1);
							item = new YJKArchUtils.StructurePoleSuit.Edge(hyendPoint, hyendPoint2, 0.0);
						}
						else
						{
							if (!(curve2.GetType() == typeof(Arc)))
							{
								continue;
							}
							Arc arc2 = this.TranslateArc(curve2 as Arc, transform);
							bool isAnticlockwise = true;
							if (arc2.Normal.IsAlmostEqualTo(-XYZ.BasisZ, 0.0001))
							{
								isAnticlockwise = false;
							}
							XYZ hyendPoint3 = arc2.GetEndPoint(0);
							XYZ hyendPoint4 = arc2.GetEndPoint(1);
							double bulge = YJKArchUtils.Utils.Geometry.GetBulge(hyendPoint3, hyendPoint4, arc2.Center, isAnticlockwise);
							item = new YJKArchUtils.StructurePoleSuit.Edge(hyendPoint3, hyendPoint4, bulge);
						}
						list4.Add(item);
					}
					SectionLoop item2 = new SectionLoop(list4);
					list.Add(item2);
				}
				SectionRegion sectionRegion = new SectionRegion(list);
				ColumnSymbol item3 = new ColumnSymbol("标准1", sectionRegion);
				List<ColumnSymbol> list5 = new List<ColumnSymbol>();
				list5.Add(item3);
				SectionTemplate sectionTemplate = new SectionTemplate(sectionRegion);
				if (familyName.CompareTo("") == 0)
				{
					familyName = "ColumnFamily";
				}
				ColumnFamily item4 = new ColumnFamily(familyName, list5, sectionTemplate);
				this.m_FamilyList.Add(item4);
				ColumnElement item5 = new ColumnElement(new XYZ(uv.U, uv.V, 0.0), 0.0, Common.MMToFeet(3500.0), 0.0, familyName, "标准1");
				this.m_ElementList.Add(item5);
			}
			catch (Exception ex)
			{
				string message2 = ex.Message;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Result CreateFamiliesAndSymbols(ref List<string> familiyPathList, ref string message)
		{
			foreach (ColumnFamily familyInfos in this.m_FamilyList)
			{
				ColumnFamilyDesiger columnFamilyDesiger = new ColumnFamilyDesiger(this.m_Revit, familyInfos, this.m_material.Id);
				string item = "";
				Result result = columnFamilyDesiger.Design(ref item, ref message);
				if (result != Autodesk.Revit.UI.Result.Succeeded)
				{
					return result;
				}
				familiyPathList.Add(item);
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Result LoadFamiliesFile(List<string> familiyPathList, ref string message)
		{
			Transaction transaction = null;
			transaction = new Transaction(this.m_Doc);
			transaction.Start("load families");
			foreach (string text in familiyPathList)
			{
				this.m_Doc.LoadFamily(text);
			}
			transaction.Commit();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Result CreateElements(XYZ selecetBoxMin, XYZ selecetBoxMax, ref string message)
		{
			Transaction transaction = null;
			transaction = new Transaction(this.m_Doc);
			transaction.Start("create elements");
			foreach (ColumnElement columnElement in this.m_ElementList)
			{
				FamilySymbol familySymbolByName = this.GetFamilySymbolByName(columnElement.ColumnFamilyName, columnElement.ColumnSymbolName);
				familySymbolByName.GetParameter("材质").Set(this.m_material.Id);
				FamilyInstance familyInstance = this.CreateOneColumn(columnElement.Position, familySymbolByName, true);
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_Doc);
				ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(familyInstance, false);
				filteredElementCollector.WherePasses(elementIntersectsElementFilter);
				filteredElementCollector.Excluding(new List<ElementId>
				{
					familyInstance.Id
				});
				foreach (Element element in filteredElementCollector)
				{
					if (element.Category.Id.IntegerValue == -2000100 || element.Category.Id.IntegerValue == -2000023 || element.Category.Id.IntegerValue == -2000014)
					{
						TaskDialog.Show("Error", "插入点已有其它不允许相交的设备存在！");
						transaction.RollBack();
						return Autodesk.Revit.UI.Result.Cancelled;
					}
				}
				foreach (Wall wall in this.GetWallsByBox(selecetBoxMin, selecetBoxMax))
				{
					this.JoinTwoElements(familyInstance, wall);
				}
			}
			transaction.Commit();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private List<Wall> GetWallsByBox(XYZ selecetBoxMin, XYZ selecetBoxMax)
		{
			List<Wall> list = new List<Wall>();
			XYZ xyz = new XYZ(selecetBoxMin.X, selecetBoxMin.Y, this.m_BottomLevel.Elevation + this.m_BottomOffset);
			XYZ xyz2 = new XYZ(selecetBoxMax.X, selecetBoxMax.Y, this.m_TopLevel.Elevation + this.m_TopOffset);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(xyz, xyz2));
			foreach (Element element in new FilteredElementCollector(this.m_Doc).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements())
			{
				if (element.GetType() == typeof(Wall))
				{
					Wall wall = element as Wall;
					if (wall.ParametersMap.Contains("已附着顶部") || wall.ParametersMap.Contains("Top is Attached"))
					{
						list.Add(wall);
					}
				}
			}
			return list;
		}

		private void JoinTwoElements(Element column, Element wall)
		{
			try
			{
				if (!JoinGeometryUtils.AreElementsJoined(this.m_Doc, column, wall))
				{
					JoinGeometryUtils.JoinGeometry(this.m_Doc, column, wall);
				}
				this.SetJoinOrder(column, wall);
			}
			catch (Exception)
			{
			}
		}

		private void SetJoinOrder(Element column, Element wall)
		{
			try
			{
				if (!JoinGeometryUtils.IsCuttingElementInJoin(this.m_Doc, column, wall))
				{
					JoinGeometryUtils.SwitchJoinOrder(this.m_Doc, column, wall);
				}
			}
			catch (Exception)
			{
			}
		}

		private FamilySymbol GetFamilySymbolByName(string familyName, string symbolName)
		{
			FamilySymbol result = null;
			foreach (Element element in new FilteredElementCollector(this.m_Doc).OfClass(typeof(Family)).ToElements())
			{
				Family family = element as Family;
				if (family != null)
				{
					Category familyCategory = RevitVersionFuncs.GetFamilyCategory(family);
					if (familyCategory != null && -2001330 == familyCategory.Id.IntegerValue && familyName.ToUpper().CompareTo(family.Name.ToUpper()) == 0)
					{
						foreach (FamilySymbol familySymbol in family.GetSymbols())
						{
							if (symbolName.ToUpper().CompareTo(familySymbol.Name.ToUpper()) == 0)
							{
								return familySymbol;
							}
						}
					}
				}
			}
			return result;
		}

		private FamilyInstance CreateOneColumn(XYZ locationPoint, FamilySymbol columType, bool isStructure)
		{
			StructuralType structuralType = 0;
			if (isStructure)
			{
                structuralType = (StructuralType)3;
			}
			UnifiedModified.ActivateFamilySymbol(columType);
			FamilyInstance familyInstance = this.m_Doc.Create.NewFamilyInstance(locationPoint, columType, this.m_BottomLevel, structuralType);
			familyInstance.get_Parameter(BuiltInParameter.SLANTED_COLUMN_TYPE_PARAM).Set(2.ToString());
			if (familyInstance != null)
			{
				Parameter parameter = familyInstance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
				if (parameter != null && this.m_BottomLevel != null)
				{
					parameter.Set(this.m_BottomLevel.Id);
				}
				Parameter parameter2 = familyInstance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
				if (parameter2 != null && this.m_TopLevel != null)
				{
					parameter2.Set(this.m_TopLevel.Id);
				}
				Parameter parameter3 = familyInstance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);
				if (parameter3 != null)
				{
					parameter3.Set(this.m_TopOffset);
				}
				Parameter parameter4 = familyInstance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);
				if (parameter4 != null)
				{
					parameter4.Set(this.m_BottomOffset);
				}
			}
			return familyInstance;
		}

		private Arc TranslateArc(Arc arc, Transform transform)
		{
			XYZ xyz = arc.GetEndPoint(0);
			XYZ xyz2 = arc.GetEndPoint(1);
			XYZ xyz3 = arc.Center;
			XYZ normal = arc.Normal;
			xyz = YJKArchUtils.Utils.Geometry.TransformPoint(xyz, transform);
			xyz2 = YJKArchUtils.Utils.Geometry.TransformPoint(xyz2, transform);
			xyz3 = YJKArchUtils.Utils.Geometry.TransformPoint(xyz3, transform);
			XYZ radianPnt = YJKArchUtils.Utils.Geometry.CalculatMidPoint(xyz, xyz2, xyz3, normal);
			if (YJKArchUtils.Utils.Geometry.Lessthan_Or_Equal((xyz2 - xyz).GetLength(), Common.MMToFeet(1.0)))
			{
				return null;
			}
			Arc result = null;
			try
			{
				result = this.m_Doc.CreatYJKArc(xyz, xyz2, radianPnt);
			}
			catch (Exception)
			{
				return null;
			}
			return result;
		}

		private Line TranslateLine(Line line, Transform transform)
		{
			XYZ xyz = line.GetEndPoint(0);
			XYZ xyz2 = line.GetEndPoint(1);
			xyz = YJKArchUtils.Utils.Geometry.TransformPoint(xyz, transform);
			xyz2 = YJKArchUtils.Utils.Geometry.TransformPoint(xyz2, transform);
			if (YJKArchUtils.Utils.Geometry.Lessthan_Or_Equal((xyz2 - xyz).GetLength(), Common.MMToFeet(1.0)))
			{
				return null;
			}
			Line result = null;
			try
			{
				result = YJKLineEx.YJKGetBound(new XYZ(xyz.X, xyz.Y, 0.0), new XYZ(xyz2.X, xyz2.Y, 0.0));
			}
			catch (Exception)
			{
				return null;
			}
			return result;
		}

		private ExternalCommandData m_Revit;

		private Document m_Doc;

		private List<ColumnFamily> m_FamilyList = new List<ColumnFamily>();

		private List<ColumnElement> m_ElementList = new List<ColumnElement>();

		private Level m_TopLevel;

		private Level m_BottomLevel;

		private double m_TopOffset;

		private double m_BottomOffset;

		private Material m_material;
	}
}
